package com.aaa.java15;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/19 11:50
 * @description：保存对象
 * @modified By：
 * @version:
 */
public class SaveObject {

    public static void main(String[] args) throws Exception {
        File file = new File("D:\\qy156\\xxx.txt");
        //序列化
       /*Person person1= new Person(1,"杨过",20,true);
       Person person2= new Person(2,"小龙女",28,false);
        List<Person> personList = new ArrayList<>();
        personList.add(person1);
        personList.add(person2);
       File file = new File("D:\\qy156\\xxx.txt");
         FileOutputStream fileOutputStream = new FileOutputStream(file);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
        objectOutputStream.writeObject(personList);
        objectOutputStream.flush();
        objectOutputStream.close();
        fileOutputStream.close();*/




       //反序列化
        System.out.println("读文件的内容");
        FileInputStream fileInputStream = new FileInputStream(file);
        ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
        List<Person> object = (List<Person>) objectInputStream.readObject();
        System.out.println(object.toString());


    }
}
